#include "Light.h"
#include "gl/gl.h"

int Light::nextNumber=0;
Light::Light()
{
    ambient = Vec4(0.00f, 0.00f, 0.00f, 1.0f);
    diffuse = Vec4(1.00f, 1.00f, 1.00f, 1.0f);
    specular = Vec4(1.00f, 1.00f, 1.00f, 1.0f);
    position = Vec4(-2.0f, 2.0f, 2.0f, 1.0f);
    //position = Vec4(0.0f, 0.0f, 0.0f, 0.0f);
    number=getNextNumber();
    on=true;    
}

Light::~Light() {}

void Light::render(float timeElapsed)
{    
     std::cout << "on " << on<<std::endl;      

         float model_ambient[4] = {1.0f, 1.0f, 1.0f, 1.0f};
         float viewpoint=0.0f;
         //scene ambient light
         //glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);
         //spec light shit
         glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, viewpoint);
         //two side light
         glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
         //ambient
         glLightfv(GL_LIGHT0+number, GL_AMBIENT, ambient.ptr());
         //diffuse
         glLightfv(GL_LIGHT0+number, GL_DIFFUSE, diffuse.ptr());
         //specular
         glLightfv(GL_LIGHT0+number, GL_SPECULAR, specular.ptr());
         //position
         glLightfv(GL_LIGHT0+number, GL_POSITION, position.ptr());
         glEnable(GL_LIGHTING);
         
         //set spot cutoff;     
         spotCutOff = 180.0f;
         //set conc
         conc=15.0f;
         //set attenuation
         atten=1.0f;
         if (on==true){
            glEnable(GL_LIGHT0+number);
         }else{glDisable(GL_LIGHT0+number);}
}

void Light::update(float timeElapsed)
{ 
     std::cout << "Updating a Light " << std::endl; 
}

void Light::setSpot(){
     /*Spot properties*/  
     //spot direction
     std::cout << "no " <<number<< std::endl; 
     std::cout << "spot on " <<GL_LIGHT0+number<< std::endl; 
     std::cout << "light " <<GL_LIGHT0<< std::endl; 
     glLightfv(GL_LIGHT0+number, GL_SPOT_DIRECTION, position.ptr());
     //angle of the cone light emitted by the spot : value between 0 to 180
     glLightf(GL_LIGHT0+number, GL_SPOT_CUTOFF, spotCutOff);
       
     //exponent propertie defines the concentration of the light
     glLightf(GL_LIGHT0+number, GL_SPOT_EXPONENT, conc);
       
     //light attenuation (default values used here : no attenuation with the distance)
     //glLightf(GL_LIGHT0+number, GL_CONSTANT_ATTENUATION, atten);
     glLightf(GL_LIGHT0+number, GL_LINEAR_ATTENUATION, 0.1f);
     //glLightf(GL_LIGHT0+number, GL_QUADRATIC_ATTENUATION, 0.0f);

}

void Light::setPos(){
}

void Light::setDirect(){
}
